home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 151-175 / scopedisk168 / serialrexx / eventmanager.rexx < prev    next >
OS/2 REXX Batch file  |  1995-03-19  |  5KB  |  200 lines

  1. /* Event Manager                             */
  2. /* trace all off                             */
  3. /*                                    */
  4. /*        port 3        port 4        port 5            */
  5. /*                                    */
  6. /*    CD    Front Door    Front Door    Stop serial        */
  7. /*    DSR    Kitchen Door    Kitchen Door    Unused            */
  8. /*    CTS    Sun Room Door    Sun Room Door    Telephone        */
  9. /*                                    */
  10. trace off
  11. portadd = openport( 'EventManager' )
  12. intruder = 0
  13. intruderold = 0
  14. doork = 0
  15. doorf = 0
  16. doors = 0
  17. do until cmd = "STOP"
  18.    do until dpacket ~= 0
  19.       packet = getpkt( 'EventManager' )
  20.       dpacket =  c2d( packet )
  21.       /*   say 'packet is ' dpacket */
  22.       if dpacket = 0
  23.       then do
  24.          flag = waitpkt( 'EventManager' )
  25.       end
  26.       else do
  27.       end
  28.    end
  29.    /* say 'We now have an event to process.  Packet is ' packet dpacket */
  30.    string = getarg( packet, 0 )
  31.    /* reply to the packet */
  32.    flag = reply( packet, 0 )
  33.    i = 0
  34.    do until blank = 0
  35.       /*   say 'string is:' string */
  36.       blank = index( string, ' ' )
  37.       if blank = 0
  38.       then do
  39.          arg = string
  40.       end
  41.       else do
  42.          arg = substr( string, 1, blank-1 )
  43.          string = substr( string, blank+1 )
  44.       end
  45.       /* say 'Arg is:' arg */
  46.       i = i + 1
  47.       select
  48.          when i = 1 then cmd  = arg
  49.          when i = 2 then arg1 = arg
  50.          when i = 3 then arg2 = arg        
  51.          when i = 4 then arg3 = arg        
  52.          when i = 5 then arg4 = arg        
  53.          otherwise say 'too many arguments'
  54.       end
  55.    end
  56.    select
  57.       when cmd = 'SERIAL' then flag = doserial( arg1, arg2, arg3 ) 
  58.       when cmd = 'STOP'   then flag = dostop( cmd )
  59.       otherwise flag = dounknown( cmd )
  60.    end
  61. end
  62. flag = closeport( 'EventManager' )
  63. exit
  64. /* --------------------------------------------------------------- */ 
  65. doserial: procedure expose intruder intruderold doork doorf doors 
  66.    arg arg1, arg2, arg3
  67.    all = arg1||arg2||arg3
  68.    /* say all */
  69.    if all = 'CTS51' | all = 'CTS50' 
  70.    then do
  71.       i = dophone( arg3 )
  72.    end
  73.    else nop
  74.    if arg2 = 3 | arg2 = 4
  75.    then do
  76.       i = dodoor( arg1, arg2, arg3 )
  77.       say 'intruder is ' intruder
  78.       if intruder & ~ intruderold
  79.       then do
  80.          address command 'execute s:start intruder'
  81.       end
  82.       else nop
  83.       intruderold = intruder
  84.    end
  85.    else nop
  86.    return 0
  87. /* --------------------------------------------------------------- */ 
  88. dophone: procedure expose offhook
  89.    arg arg3
  90.    if arg3 = '0' 
  91.    then do
  92.       say 'hang up phone'
  93.    end
  94.    else do
  95.       say 'answer phone'
  96.       address command 'execute x:phone1.scr'
  97.    end
  98.    return 0
  99. /* --------------------------------------------------------------- */ 
  100. dodoor: procedure expose intruder doork doorf doors
  101.    arg arg1, arg2, arg3
  102.    all = arg1||arg2||arg3
  103.    opened = 0
  104.    closed = 0
  105.    if all = 'CD31' | all = 'CD40'
  106.    then i = opendoor( arg1 )
  107.    else nop
  108.    if all = 'DSR31' | all = 'DSR40'
  109.    then i = opendoor( arg1 )
  110.    else nop
  111.    if all = 'CTS31' | all = 'CTS40'
  112.    then i = opendoor( arg1 )
  113.    else nop
  114.    if all = 'CD30' | all = 'CD41'
  115.    then i = closedoor( arg1 )
  116.    else nop
  117.    if all = 'DSR30' | all = 'DSR41'
  118.    then i = closedoor( arg1 )
  119.    else nop
  120.    if all = 'CTS30' | all = 'CTS41'
  121.    then i = closedoor( arg1 )
  122.    else nop
  123.    if closed
  124.    then do
  125.       if doork = 0 & doorf = 0 & doors = 0
  126.       then do
  127.          intruder = 0
  128.       end
  129.       else nop
  130.    end
  131.    else nop
  132.    if opened
  133.    then do
  134.       intruder = 1
  135.    end
  136.    else nop
  137.    say 'doork doorf doors ' doork doorf doors
  138.    return 0
  139. /* --------------------------------------------------------------- */ 
  140. opendoor: procedure expose opened doork doorf doors
  141.    arg door
  142.    if door = 'CD'
  143.    then do
  144.       say 'opened front door'
  145.       opened = 1
  146.       doorf = 1
  147.    end
  148.    else nop
  149.    if door = 'DSR'
  150.    then do
  151.       say 'opened kitchen door'
  152.       opened = 1
  153.       doork = 1
  154.    end
  155.    else nop
  156.    if door = 'CTS'
  157.    then do
  158.       say 'opened sun room door'
  159.       opened = 1
  160.       doors = 1
  161.    end
  162.    else nop
  163.    return 0
  164. /* --------------------------------------------------------------- */ 
  165. closedoor: procedure expose closed doork doorf doors
  166.    arg door
  167.    if door = 'CD'
  168.    then do
  169.       say 'closed front door'
  170.       closed = 1
  171.       doorf = 0
  172.    end
  173.    else nop
  174.    if door = 'DSR'
  175.    then do
  176.       say 'closed kitchen door'
  177.       closed = 1
  178.       doork = 0
  179.    end
  180.    else nop
  181.    if door = 'CTS'
  182.    then do
  183.       say 'closed sun room door'
  184.       closed = 1
  185.       doors = 0
  186.    end
  187.    else nop
  188.    return 0
  189. /* --------------------------------------------------------------- */ 
  190. dounknown: procedure 
  191.    arg cmd
  192.    say 'Unknown command: ' cmd
  193.    return 0
  194. /* --------------------------------------------------------------- */ 
  195. dostop: procedure 
  196.    arg cmd
  197.    say 'Preparing to stop.'
  198.    return 0
  199. /* --------------------------------------------------------------- */ 
  200.